package com.maolong.springbootstartordercenter.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class PlusController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/plus")
    public String plus(@RequestParam String id){
        log.info("id:{}",id);
        CorrelationData correlationData = new CorrelationData(id);

        MessagePostProcessor processor=message -> {
            message.getMessageProperties().setDelay(5000);
            return message;
        };

        rabbitTemplate.convertAndSend("spring-plus-exchange","spring.plus",id,processor,correlationData);
        return "ok";
    }
}
